package com.dede.net_speed_monitor.util;

import android.app.ActivityManager;
import android.content.Context;

import java.util.List;

/**
 * Created by Hsh
 * in 2017/5/20 020 2:07 下午 on ACER-PC computer.
 * doc.
 */
public class ServiceUtil {

    /**
     * 校验某个服务是否还存在
     */
    public static boolean isServiceRunning(Context context, String serviceName) {
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningServiceInfo> services = am.getRunningServices(100);
        for (ActivityManager.RunningServiceInfo info : services) {
            String name = info.service.getClassName();
            if (serviceName.equals(name)) {
                return true;
            }
        }
        return false;
    }

    private ServiceUtil() {
    }
}
